package com.hsmpay.utils;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import com.hsmpay.utils.system.ConConfig;

public class WriteFile {
//	File f;
//	File dirFile;
//	FileWriter fw;
//	BufferedWriter bw;
//	Date now;
//	SimpleDateFormat df;
//	SimpleDateFormat df2;
//	String date;
//	String date2;
	String Path = ConConfig.getAttribute("PAY_LOG");//"D:\\JxfsClient\\";
	boolean bFile=false;
	
	String fileSuffix = null;
	String fileDir = null;
	public WriteFile(String fileSuffix){
		this.fileSuffix = fileSuffix;
		this.fileDir = fileSuffix;
	}
	public WriteFile(String fileDir,String fileSuffix){
		this.fileSuffix = fileSuffix;
		this.fileDir = fileDir;
	}
	
	public void log(String ms,String Level) {
		File f;
		//File dirFile;
		FileWriter fw;
		BufferedWriter bw;
		//Date now;
		SimpleDateFormat df;
		SimpleDateFormat df2;
		String date;
		String date2;
		try{
			//now = new Date(); 
			df = new SimpleDateFormat("yyyyMMdd");
			df2 = new SimpleDateFormat("yyyy-MM");
			date = df.format(new Date()); 
			date2 = df2.format(new Date());
			String nowtime=new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()); 
			String baseDir = Path+"Log"+File.separator+date2+File.separator+fileDir;
			creteFloder(baseDir);
			//log.debug("日志文件路径-------------------"+(baseDir+File.separator+date+"-"+fileSuffix+".txt"));
			f= new File(baseDir+File.separator+date+"-"+fileSuffix+".txt");
		
		    if (!(f.exists())){//LOGLog.txt是否存在
				f.createNewFile();
			}
			fw = new FileWriter(f,true);
			bw=new BufferedWriter(fw);
			//bw.write(nowtime+"    ["+Level+"]    "+ms);
			bw.append(nowtime+"    ["+Level+"]    "+ms);
			bw.newLine();
			bw.flush();
			bw.close();
		}catch (Exception e) {
			e.printStackTrace();
		}
	}
	public void creteFloder(String fld){
		File dirFile = new File(fld);
		if(!dirFile.exists()){
			dirFile.mkdirs();
		}
	}
	public void main(String[] args) throws Exception {
		WriteFile wf = new WriteFile("anxinyb");
		wf.log("1234567890","调试");
	}
	
}